home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / comm / term / vltj5867.lha / VLT / rexx / AutoWrap.vlt < prev    next >
Text File  |  1994-03-27  |  2KB  |  71 lines

  1. /** AutoWrap.vlt
  2. *
  3. *   Example program to intercept keystrokes.
  4. *   This one implements automatic wrapping.
  5. *
  6. **/
  7. margincol = 72
  8. /*
  9. *   Add libraries if necessary
  10. */
  11. if show("l", "rexxarplib.library") = 0 then do
  12.    check = addlib('rexxsupport.library', 0, -30, 0)
  13.    check = addlib('rexxarplib.library',  0, -30, 0)
  14. end
  15. /*
  16. *   Open a port
  17. */
  18. mp = openport(MARGIN_BELL)
  19. /*
  20. *   Tell VLT to send us stuff
  21. */
  22. "wedge keystrokes MARGIN_BELL"
  23. /*
  24. *   Loop until quitflag is 1, waiting for packets
  25. */
  26. do forever
  27.    if quitflag = 1 then leave
  28.    t = waitpkt(MARGIN_BELL)
  29. /*
  30. *   We got a number of packets. Loop over all of them.
  31. */
  32.    do ff = 1
  33.       p = getpkt(MARGIN_BELL)
  34.       if c2d(p) = 0 then leave ff
  35.       line = getarg(p)
  36. /*
  37. *   Got something. Find out what...
  38. */
  39.       parse var line command code qual iaddr char .
  40. /*
  41. *   If we got an "esc", quit.
  42. */
  43.       if char = '1B'x then do
  44.          quitflag = 1
  45.          "$1: BEEP; delay .7; BEEP; delay .7; BEEP"
  46.       end
  47. /*
  48. *   Else check the current cursor x position. Send VLT a BEEP command if it
  49. *   is at the margin column.
  50. */
  51.       else do
  52.          "extract x"
  53.          if VLT.x >= margincol then do
  54.             "extract reviewlineatcursor"
  55.             s = reverse(VLT.reviewlineatcursor)
  56.             n = index(s, " ")
  57.             if n > 0 then do
  58.                "send ("copies('08'x, n)")"
  59.                "emit ("copies('08'x, n)")"
  60.                if n > 1 then do
  61.                   "send (*R"reverse(substr(s, 1, n - 1))")"
  62.                   "emit (*R"reverse(substr(s, 1, n - 1))")"
  63.                end
  64.             end
  65.          end
  66.       end
  67.       t = reply(p, 1)
  68.    end
  69. end
  70.  
  71.